using MicroMsg.Plugin;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace MicroMsg.UI.UserContrl
{
	public class HubPluginCtrlBase : UserControl
	{
		public delegate void ListItemClick(object sender, object object_0);
		private const int cNAniDur = 500;
		private const int cNAniStartTime = 5000;
		private const int cDOriginOffset = 0;
		private const int cDMaxOffset = 136;
		private bool mBIsLoaded;
		public static DependencyProperty ListItemProperty = DependencyProperty.Register("ItemObject", typeof(PluginBase), typeof(HubPluginCtrlBase), new PropertyMetadata(null, new PropertyChangedCallback(HubPluginCtrlBase.OnItemPropertyChanged)));
		public static DependencyProperty strImageSourceProperty = DependencyProperty.Register("strImageSource", typeof(string), typeof(HubPluginCtrlBase), new PropertyMetadata(null, new PropertyChangedCallback(HubPluginCtrlBase.OnstrImageSourcePropertyChanged)));
		public static DependencyProperty strWordingProperty = DependencyProperty.Register("strWording", typeof(string), typeof(HubPluginCtrlBase), new PropertyMetadata(null, new PropertyChangedCallback(HubPluginCtrlBase.OnstrWordingPropertyChanged)));
		private Storyboard mSbPageAni;
		private static int[] cAKeyAniTime = new int[]
		{
			2500,
			3000,
			8000,
			8500
		};
		private static double[] cAKeyAniValue;
		public event HubPluginCtrlBase.ListItemClick ItemClick;
		public PluginBase ItemObject
		{
			get
			{
				return (PluginBase)base.GetValue(HubPluginCtrlBase.ListItemProperty);
			}
			set
			{
				base.SetValue(HubPluginCtrlBase.ListItemProperty, value);
			}
		}
		public string strImageSource
		{
			get
			{
				return (string)base.GetValue(HubPluginCtrlBase.strImageSourceProperty);
			}
			set
			{
				base.SetValue(HubPluginCtrlBase.strImageSourceProperty, value);
			}
		}
		public string strWording
		{
			get
			{
				return (string)base.GetValue(HubPluginCtrlBase.strWordingProperty);
			}
			set
			{
				base.SetValue(HubPluginCtrlBase.strWordingProperty, value);
			}
		}
		protected virtual Grid GridPrePage
		{
			get;
			set;
		}
		protected virtual CompositeTransform TransContent
		{
			get;
			set;
		}
		protected virtual Image FlagIcon
		{
			get;
			set;
		}
		protected virtual TextBlock TxtNotifyCnt
		{
			get;
			set;
		}
		protected virtual DynamicTextBlock TxtTitle
		{
			get;
			set;
		}
		protected virtual Image ImgIcon
		{
			get;
			set;
		}
		public HubPluginCtrlBase()
		{
			base.add_Loaded(new RoutedEventHandler(this.HubPluginCtrlBase_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.HubPluginCtrlBase_Unloaded));
		}
		private void HubPluginCtrlBase_Loaded(object sender, RoutedEventArgs e)
		{
			this.mBIsLoaded = true;
			this.tryResumePageAni();
			this.adjustFlagImagePosition();
		}
		private void HubPluginCtrlBase_Unloaded(object sender, RoutedEventArgs e)
		{
			this.mBIsLoaded = false;
			this.pauseChangePageAni();
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == HubPluginCtrlBase.ListItemProperty)
			{
				(dependencyObject_0 as HubPluginCtrlBase).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue())
				{
					this.ItemObject.SetFFEntryCallBack(new StandardUITaskDlg(this.PluginCallBack));
					this.RefreshItem();
				}
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
		}
		private static void OnstrImageSourcePropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == HubPluginCtrlBase.strImageSourceProperty)
			{
				(dependencyObject_0 as HubPluginCtrlBase).strImageSourcePropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void strImageSourcePropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				object arg_0F_0 = dependencyPropertyChangedEventArgs_0.get_OldValue();
				object arg_0E_0 = dependencyPropertyChangedEventArgs_0.get_NewValue();
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
		}
		private static void OnstrWordingPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == HubPluginCtrlBase.strWordingProperty)
			{
				(dependencyObject_0 as HubPluginCtrlBase).strWordingPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void strWordingPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				object arg_0F_0 = dependencyPropertyChangedEventArgs_0.get_OldValue();
				object arg_0E_0 = dependencyPropertyChangedEventArgs_0.get_NewValue();
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
		}
		public void tryResumePageAni()
		{
			if (this.mBIsLoaded && this.GridPrePage.get_Children().get_Count() != 0)
			{
				this.resumeChangePageAni();
			}
		}
		public void startChangePageAni()
		{
			this.stopChangePageAni();
			this.mSbPageAni = new Storyboard();
			DoubleAnimation doubleAnimation = ToolFunction.createAnimation(new double?(0.0), 136.0, this.TransContent, "TranslateY", 500u);
			doubleAnimation.set_BeginTime(new TimeSpan?(TimeSpan.FromMilliseconds(0.0)));
			this.mSbPageAni.get_Children().Add(doubleAnimation);
			doubleAnimation = ToolFunction.createAnimation(new double?(0.0), 0.0, this.TransContent, "TranslateX", 0u);
			doubleAnimation.set_BeginTime(new TimeSpan?(TimeSpan.FromMilliseconds(3000.0)));
			this.mSbPageAni.get_Children().Add(doubleAnimation);
			this.mSbPageAni.set_AutoReverse(true);
			this.mSbPageAni.set_FillBehavior(1);
			this.mSbPageAni.add_Completed(new EventHandler(this.mSbPageAni_Completed));
			this.mSbPageAni.Begin();
		}
		public void mSbPageAni_Completed(object sender, EventArgs e)
		{
			this.stopChangePageAni();
			CircleHubPrevCtrl circleHubPrevCtrl = (CircleHubPrevCtrl)UIElementTraveler.FindElementRecursive(this.GridPrePage, typeof(CircleHubPrevCtrl));
			if (circleHubPrevCtrl != null)
			{
				circleHubPrevCtrl.RefreshImg();
			}
			List<UITask> list = new List<UITask>();
			list.Add(new UITask(new UITaskDlg(this.tryResumePageAni), 0u));
			UITaskManager uITaskManager = new UITaskManager(list, null);
			uITaskManager.StartTasks(5000u);
		}
		public void pauseChangePageAni()
		{
			if (this.mSbPageAni != null)
			{
				this.mSbPageAni.Pause();
			}
		}
		public void resumeChangePageAni()
		{
			if (this.mSbPageAni != null)
			{
				this.mSbPageAni.Resume();
				return;
			}
			this.startChangePageAni();
		}
		public void stopChangePageAni()
		{
			if (this.mSbPageAni != null)
			{
				this.mSbPageAni.Stop();
				this.mSbPageAni = null;
				base.UpdateLayout();
			}
		}
		protected virtual void adjustFlagImagePosition()
		{
		}
		protected virtual void RefreshItem()
		{
		}
		public void OnLanguageChange()
		{
			if (this.ItemObject == null)
			{
				base.set_Visibility(1);
				return;
			}
			base.set_Visibility(0);
			this.ImgIcon.set_Source(this.ItemObject.mIconInFFEntry);
			this.TxtTitle.Text = this.ItemObject.mFFEntryTitle;
			this.adjustFlagImagePosition();
			if (this.GridPrePage.get_Children().get_Count() != 0)
			{
				HubPlugCtrlPrevPageBase hubPlugCtrlPrevPageBase = this.GridPrePage.get_Children().get_Item(0) as HubPlugCtrlPrevPageBase;
				if (hubPlugCtrlPrevPageBase != null)
				{
					hubPlugCtrlPrevPageBase.OnLanguaeChange();
				}
			}
		}
		protected void LayoutRoot_Click(object sender, object args)
		{
			if (this.ItemObject != null)
			{
				this.ItemObject.execute(3, null);
			}
			if (this.ItemClick != null)
			{
				this.ItemClick(this, this.ItemObject);
			}
		}
		public object PluginCallBack(object obj1, object obj2)
		{
			if (!(obj1 is FFEntryCtrlOpKind))
			{
				return null;
			}
			switch ((FFEntryCtrlOpKind)obj1)
			{
			case FFEntryCtrlOpKind.OpKind_Cnt:
				if (obj2 is int)
				{
					int num = (int)obj2;
					if (num == 0)
					{
						this.TxtNotifyCnt.set_Visibility(1);
					}
					else
					{
						if (num > 99)
						{
							num = 99;
						}
						this.TxtNotifyCnt.set_Text(string.Concat(num));
						this.TxtNotifyCnt.set_Visibility(0);
					}
				}
				return null;
			case FFEntryCtrlOpKind.OpKind_SetPrePageContent:
			{
				if (this.GridPrePage == null)
				{
					return null;
				}
				this.GridPrePage.get_Children().Clear();
				UIElement uIElement = obj2 as UIElement;
				if (uIElement != null)
				{
					if (uIElement is CircleHubPrevCtrl && uIElement is CircleHubPrevCtrl)
					{
						CircleHubPrevCtrl circleHubPrevCtrl = uIElement as CircleHubPrevCtrl;
						if (circleHubPrevCtrl.get_Parent() == null)
						{
							this.GridPrePage.get_Children().Add(circleHubPrevCtrl);
						}
					}
					this.tryResumePageAni();
				}
				else
				{
					this.stopChangePageAni();
				}
				break;
			}
			case FFEntryCtrlOpKind.OpKind_UpdateFootPrint:
				this.FlagIcon.set_Visibility(this.ItemObject.isShowFlagImage() ? 0 : 1);
				break;
			}
			return null;
		}
		static HubPluginCtrlBase()
		{
			// Note: this type is marked as 'beforefieldinit'.
			double[] array = new double[4];
			array[1] = 136.0;
			array[2] = 136.0;
			HubPluginCtrlBase.cAKeyAniValue = array;
		}
	}
}
